﻿package mortal.common.tools
{
    import mortal.game.manager.*;

    public class DateUtil extends Object
    {
        private static var localTimeZone:int = -8;

        public function DateUtil()
        {
            return;
        }// end function

        public static function getTotalDays(param1:Date) : int
        {
            if (param1 == null)
            {
                return 0;
            }
            return int((param1.time - localTimeZone * 60 * 60 * 1000) / (24 * 60 * 60 * 1000));
        }// end function

        public static function isSameDay(param1:Date, param2:Date) : Boolean
        {
            return param1.fullYear == param2.fullYear && param1.month == param2.month && param1.day == param2.day;
        }// end function

        public static function getDayDis(param1:Date, param2:Date) : int
        {
            var _loc_3:* = getTotalDays(param1);
            var _loc_4:* = getTotalDays(param2);
            return _loc_4 - _loc_3;
        }// end function

        public static function isInDate(param1:Date, param2:Date) : Boolean
        {
            if (param1 && param2 && param1.time <= ClockManager.instance.nowDate.time && param2.time > ClockManager.instance.nowDate.time)
            {
                return true;
            }
            return false;
        }// end function

        public static function getSecondsDis(param1:Date, param2:Date, param3:Boolean = false) : int
        {
            var _loc_4:* = (param2.time - param1.time) / 1000;
            if (param3 && _loc_4 < 0)
            {
                _loc_4 = 0;
            }
            return _loc_4;
        }// end function

        public static function getDateByHourAndMin(param1:String) : Date
        {
            var _loc_2:* = ClockManager.instance.nowDate;
            var _loc_3:* = param1.split(":");
            if (_loc_3.length == 3)
            {
                return new Date(_loc_2.fullYear, _loc_2.month, _loc_2.date, Number(_loc_3[0]), Number(_loc_3[1]), Number(_loc_3[2]));
            }
            return new Date(_loc_2.fullYear, _loc_2.month, _loc_2.date, Number(_loc_3[0]), Number(_loc_3[1]));
        }// end function

        public static function getDateByFullTimeString(param1:String) : Date
        {
            var _loc_2:* = param1.split(" ");
            var _loc_3:* = /\s""\s/g;
            var _loc_4:* = _loc_2[0].replace(_loc_3, "");
            var _loc_5:* = _loc_2[1].replace(_loc_3, "");
            var _loc_6:* = _loc_4.split("-");
            var _loc_7:* = _loc_5.split(":");
            var _loc_8:* = int(_loc_6[0]);
            var _loc_9:* = int(_loc_6[1]) - 1;
            var _loc_10:* = int(_loc_6[2]);
            var _loc_11:* = int(_loc_7[0]);
            var _loc_12:* = int(_loc_7[1]);
            var _loc_13:* = _loc_7[2].split(".");
            var _loc_14:* = int(_loc_13[0]);
            var _loc_15:* = int(_loc_13[1]);
            return new Date(_loc_8, _loc_9, _loc_10, _loc_11, _loc_12, _loc_14, _loc_15);
        }// end function

        public static function getStrTimeByDate(param1:Date) : String
        {
            var _loc_2:* = param1.fullYear + "-" + (param1.month + 1) + "-" + param1.date + " " + param1.hours + ":" + param1.minutes + ":" + param1.seconds;
            return _loc_2;
        }// end function

    }
}
